<?php

class g5_admin_user extends Model{

	function __construct(){
		parent::__construct();
        $this->_tableName = 'g5_admin_user';
	}



    /*
    * 获取用户信息
    * @param int 用户编号
    * return array 设置SESSION信息
    **/
	function getUser($user_id = 0){
        $select = 'g5_admin_user.*,g5_admin_group.group_name,g5_admin_group.group_value,g5_admin_group.group_id,g5_admin_group.platform';
        $join   = array('g5_admin_group'=>'group_id=group_id');
        return $this->join($join)->getOne($select, array('user_id'=>$user_id));
	}
    /*
    * 获取用户列表
    **/
    function userlist() {
		return  $this->join(array('g5_admin_group'=>'group_id=group_id'))->by('user_status')->getAll('user_id,user_name,user_true_name,user_status,group_value');
    }

    /**
     * 维护用户组的游戏权限的同时增加该用户组下面所有用户的游戏权限
     * @param $groupId
     * @param $games
     * @author Giles giles.wang@icloud.com
     */
    function setGameByGroup($groupId, $games)
    {
        $res = $this->getAll('user_id', array('group_id' => $groupId));
        foreach($res as $val) {
            $this->update(array('user_games' => $games), array('user_id' => $val['user_id']));
        }
    }
}

